﻿using System;
using Nb.Common.Encrypt;
using Nb.LMS.Domains.Accounts;
using Nb.LMS.Domains.Accounts.Abstracts;

namespace Nb.LMS.Infrastructures.Accounts
{
    public class AccountPolicyService : IAccountPolicyService
    {
        private readonly NbEncryptHelper _helper;

        public AccountPolicyService(NbEncryptHelper helper)
        {
            _helper = helper;
        }
        public AccountPolicy GetAccountPolicy()
        {
            //todo read from config
            return new AccountPolicy();
        }

        public string EncryptPassword(string password, PasswordFormat format = PasswordFormat.Hashed, string salt = "")
        {
            string encryptPass;
            switch (format)
            {
                case PasswordFormat.Clear:
                    encryptPass = password;
                    break;
                case PasswordFormat.Hashed:
                    encryptPass = _helper.Hash(password + salt);
                    break;
                case PasswordFormat.Encrypted:
                    encryptPass = _helper.EncryptSymmetric(password);
                    break;
                default:
                    throw new ArgumentOutOfRangeException("format");
            }
            return encryptPass;
        }
    }
}